package net.neiquan.neiquandemowithkf.api;


import com.loopj.android.http.RequestParams;

import net.neiquanlib.http.NetCallBack;


/**
 * Description
 * Author by wangHaitao(a758277560@gmail.com)
 * Created  on 2015/12/1.
 * Version 1.0
 */
public class NetUtils {


    private static NetUtils single = null;

    // 静态工厂方法
    public static NetUtils getInstance() {
        if (single == null) {
            single = new NetUtils();
        }
        return single;
    }


    private void norPost(String url, RequestParams params, final NetCallBack callback, final Class classType) {
        HttpUtil.post(url, params, callback, classType);
    }

    private void norPostList(String url, RequestParams params, final NetCallBack callback, final Class classType) {
        HttpUtil.postList(url, params, callback, classType);
    }

    /*===================用户相关=================*/

    /**
     * 验证码
     *
     * @param phone     手机号
     * @param callback  回调
     * @param classType class
     */

    public void getCaptcha(String phone, final NetCallBack callback, final Class classType) {
        RequestParams params = new RequestParams();
        params.put("phone", phone);
        norPost(APPURL.CAPTCHA, params, callback, classType);
    }

    /**
     * 登录
     *
     * @param account
     * @param password
     * @param callback
     * @param classType
     */
    public void login(String account, String password, final NetCallBack callback, final Class classType) {
        RequestParams params = new RequestParams();
        params.put("account", account);
        params.put("password", password);
        norPost(APPURL.LOGIN, params, callback, classType);
    }

    /**
     * 注册
     *
     * @param callback
     * @param classType
     */
    public void register(String phone, String code, String password, final NetCallBack callback, final Class classType) {
        RequestParams params = new RequestParams();
        params.put("phone", phone);
        params.put("code", code);
        params.put("password", password);
        norPost(APPURL.REGIST, params, callback, classType);
    }

    /**
     * 找回密码
     *
     * @param phone
     * @param code      1.4忘记密码
     * @param callback
     * @param classType
     */
    public void passwordFind(String phone, String code, String password, final NetCallBack callback, final Class classType) {
        RequestParams params = new RequestParams();
        params.put("phone", phone);
        params.put("code", code);
        params.put("password", password);
        norPost(APPURL.PASSWORD_FIND, params, callback, classType);
    }

    /**
     * 重置密码
     *
     * @param oldPwd
     * @param newPwd
     * @param callback
     * @param classType
     */
    public void passwordReset(String oldPwd, String newPwd, final NetCallBack callback, final Class classType) {
        RequestParams params = new RequestParams();
        params.put("oldPassword", oldPwd);
        params.put("newPassword", newPwd);
        norPost(APPURL.PASSWORD_RESET, params, callback, classType);
    }

    /**
     * 修改个人信息
     *
     * @param sex
     * @param nickName
     * @param headUrl
     * @param callback
     * @param classType
     */
    public void userInfo(String headUrl, String nickName, int sex, final NetCallBack callback, final Class classType) {
        RequestParams params = new RequestParams();
        params.put("sex", sex);
        params.put("nickName", nickName);
        params.put("headUrl", headUrl);
        norPost(APPURL.UPDATE_PERSONINFO, params, callback, classType);
    }

    /**
     * 消息
     *
     * @param callback
     * @param classType
     */
    public void message(int nowPage, int pageSize, final NetCallBack callback, final Class classType) {
        RequestParams params = new RequestParams();
        params.put("nowPage", nowPage);
        params.put("pageSize", pageSize);
        norPostList(APPURL.CAPTCHA, params, callback, classType);
    }

    public void hotCommodity(final NetCallBack callback, final Class classType) {
        RequestParams params = new RequestParams();
        norPostList(APPURL.HOT_COMMODITY, params, callback, classType);
    }
}
